﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SmartPhoneClient
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < Infomation.CheckedOrder.Length; i++)
            {
                TreeNode orderItem = new TreeNode();
                
                string itemState = "待做";
                if (Infomation.CheckedOrder[i].itemState == "0")
                {
                    itemState = "待做";
                    orderItem.SelectedImageIndex = 0;
                }
                else if (Infomation.CheckedOrder[i].itemState == "1")
                {
                    itemState = "正在做";
                    orderItem.SelectedImageIndex = 1;
                }
                else if (Infomation.CheckedOrder[i].itemState == "2")
                {
                    itemState = "已做完";
                    orderItem.SelectedImageIndex = 2;
                }

                orderItem.Text = Infomation.CheckedOrder[i].foodID + "  " + Infomation.CheckedOrder[i].foodName + "  " + Infomation.CheckedOrder[i].custNotes + "  " + itemState; 
                orderItem.Tag = Infomation.CheckedOrder[i].itemID;
                treeView1.Nodes.Add(orderItem);
            }
        }

        /// <summary>
        /// “加菜”按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem2_Click(object sender, EventArgs e)
        {
            Form5 f5 = new Form5();
            f5.Show();
        }


        /// <summary>
        /// “删菜”按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuItem3_Click(object sender, EventArgs e)
        {
            if (treeView1.SelectedNode.SelectedImageIndex == 0)
            {
                string itemID = (string)treeView1.SelectedNode.Tag;
                string command = "DeleteOrderItem|" + itemID + "|" + Infomation.tableID;
                Byte[] outbytes = System.Text.Encoding.Unicode.GetBytes(command.ToCharArray());
                Infomation.MySocket.Send(outbytes, outbytes.Length, 0);
                treeView1.SelectedNode.Remove();
            }
            else if (treeView1.SelectedNode.SelectedImageIndex == 1)
            {
                MessageBox.Show("此菜正在制作中，无法取消");
            }
            else if (treeView1.SelectedNode.SelectedImageIndex == 2)
            {
                MessageBox.Show("此菜已经做完，无法取消");
            }
            else
            {
                MessageBox.Show("此菜状态有误，状态值为：" + treeView1.SelectedNode.SelectedImageIndex.ToString());
            }
        }

        private void menuItem4_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}